package com.luotao.test.netty.jsonnio;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-30
 * Time: 00:46
 */

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;

/**
 * 消息编码器
 *
 */
public class ClientMessageEncoder extends LengthFieldPrepender {

	public ClientMessageEncoder(int lengthFieldLength) {
		super(lengthFieldLength);
	}

	@Override
	protected Object encode(ChannelHandlerContext ctx, Channel channel,
			Object obj) throws Exception {

//		ChannelBuffer ob = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());
//
//		String message = (String)obj;
//        System.out.println("message = " + message);
//		byte[] strBytes = message.getBytes();
//		ob.writeInt(strBytes.length);
//		ob.writeBytes(strBytes);
//
//		return super.encode(ctx, channel, ob);

     //    ChannelBuffer ob = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());

	//	ChannelBuffer ch = (ChannelBuffer) obj;
//        System.out.println("message = " + message);
//		byte[] strBytes = message.getBytes();
//		ob.writeInt(strBytes.length);
	//	ob.writeBytes(ch.array());

		return super.encode(ctx, channel, obj);


	}

}
